package com.zhixiang.xaec.entity;


import org.apache.commons.beanutils.BeanUtils;
import org.hibernate.annotations.GenericGenerator;
import org.hibernate.cfg.Comment;

import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.MappedSuperclass;
import java.util.Map;


/**
 * 统一定义id的entity基类.
 * 
 * 
 */
@MappedSuperclass
public class BaseIdEntity extends BaseEntity
{
    @Id
    @Comment("主键，流水号自动增长")
    @GenericGenerator(name = "idGenerator",strategy = "com.zhixiang.core.util.IdGenerator")
    @GeneratedValue(generator = "idGenerator")
    public Long id;

    public Long getId()
    {
        return id;
    }

    public void setId(Long id)
    {
        this.id = id;
    }

    @Override
    public String toString()
    {
        StringBuffer buf = new StringBuffer();
        try
        {
            Map<String, String> map = BeanUtils.describe(this);
            return map.toString();
        }
        catch (Exception e)
        {
            buf.append("BeanUtils describe bean occur exception:" + e.getMessage());
            return buf.toString();
        }
        //return ToStringBuilder.reflectionToString(this);
    }
}
